package pcjavanet.mobilesell.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import pcjavanet.mobilesell.model.Color;
import pcjavanet.mobilesell.model.Employee;
import pcjavanet.mobilesell.model.Shop;
import pcjavanet.mobilesell.model.PageBean;
import pcjavanet.mobilesell.model.QryCondition;
import pcjavanet.mobilesell.service.ShopService;
import pcjavanet.util.LogUtil;

import com.opensymphony.xwork2.ActionSupport;
@Namespace("/shop")
@Controller
@Scope("prototype")
@ParentPackage("json-default")
@Results({
	@Result(name = "success", location = "/view/Shop.jsp"),
	@Result(name = "input", location = "/view/Shop.jsp")
})

public class ShopAction  extends ActionSupport {

  @Resource
  private ShopService shopService;
  private   java.lang.Integer dbid ;
  private   java.lang.String name ;
  private   java.lang.String shoptype ;
  private   java.lang.String manager ;
  private   java.lang.String telephone ;
  private   java.lang.String tax ;
  private   java.lang.String address ;
  private   java.util.Date createDate ;
  private int start  ;
  private int limit  ;
  private int totalProperty  ;
  private boolean success = true ;
  private String  info ;
  private List<Shop>  shopPageBeans  ;
  public    java.lang.Integer getDbid() {
   	return this.dbid;
  }
  public void setDbid(  java.lang.Integer  dbid) {
   	 this.dbid=dbid;
  }
  public    java.lang.String getName() {
   	return this.name;
  }
  public void setName(  java.lang.String  name) {
   	 this.name=name;
  }
  public    java.lang.String getShoptype() {
   	return this.shoptype;
  }
  public void setShoptype(  java.lang.String  shoptype) {
   	 this.shoptype=shoptype;
  }
  public    java.lang.String getManager() {
   	return this.manager;
  }
  public void setManager(  java.lang.String  manager) {
   	 this.manager=manager;
  }
  public    java.lang.String getTelephone() {
   	return this.telephone;
  }
  public void setTelephone(  java.lang.String  telephone) {
   	 this.telephone=telephone;
  }
  public    java.lang.String getTax() {
   	return this.tax;
  }
  public void setTax(  java.lang.String  tax) {
   	 this.tax=tax;
  }
  public    java.lang.String getAddress() {
   	return this.address;
  }
  public void setAddress(  java.lang.String  address) {
   	 this.address=address;
  }
  public    java.util.Date getCreateDate() {
   	return this.createDate;
  }
  public void setCreateDate(  java.util.Date  createDate) {
   	 this.createDate=createDate;
  }
  public  void setStart(int start) {
   	 this.start = start;
  }
  public  void setLimit(int limit) {
   	 this.limit = limit;
  }
  public  void setTotalProperty(int totalProperty) {
   	 this.totalProperty = totalProperty;
  }
  public  void setShopPageBeans(List<Shop> shopPageBeans){
   	 this.shopPageBeans =shopPageBeans  ;
  }
  public  int getStart( ) {
   	 return this.start;
  }
  public  int getLimit( ) {
   	 return this.limit;
  }
  public  int getTotalProperty( ) {
   	 return this.totalProperty;
  }
  public    List<Shop> getShopPageBeans(){
   	 return this.shopPageBeans   ;
  }
  public  String getInfo( ) {
   	 return this.info;
  }
  public  void setInfo(String info){
   	 this.info = info ;
  }
  public  boolean getSuccess( ) {
   	 return this.success;
  }
  public  void setSuccess(boolean success){
   	 this.success = success ;
  }

  @Action(value="insertShop",results = {@Result(name = "success", type = "json")})
  public String  insertShop() throws Exception{
   	success = false ;
   	info = "" ;
  	Shop bean = new Shop();
  	bean.setName(this.name); 
  	bean.setShoptype(this.shoptype); 
  	bean.setManager(this.manager); 
  	bean.setTelephone(this.telephone); 
  	bean.setTax(this.tax); 
  	bean.setAddress(this.address); 
  	bean.setCreateDate(this.createDate); 
	shopService.insert(bean);
	javax.servlet.http.HttpServletRequest request =(javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST);
	Object empolyeeBean =  request.getSession().getAttribute("employee") ;
	if (  empolyeeBean != null ) {
		int refEmployeeDbid = ( ( Employee ) empolyeeBean).getDbid();
		 LogUtil.addLog(refEmployeeDbid, LogUtil.OPERATOR_KEY_INSERT , Color.MODULE_ID );
	}
   	success = true ;
   	info = "Add Successful" ;
   	return SUCCESS;
  }

  @Action(value="queryShop",results = {@Result(name = "success", type = "json")})
  public String  queryShop() throws Exception{
  	Shop bean = new Shop();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setShoptype(this.shoptype); 
  	bean.setManager(this.manager); 
  	bean.setTelephone(this.telephone); 
  	bean.setTax(this.tax); 
  	bean.setAddress(this.address); 
  	bean.setCreateDate(this.createDate); 
	shopService.selectByPrimaryKey(bean);
   	return SUCCESS;
  }

  @Action(value="updateShop",results = {@Result(name = "success", type = "json")})
  public String  updateShop() throws Exception{
   	success = false ;
   	info = "" ;
  	Shop bean = new Shop();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setShoptype(this.shoptype); 
  	bean.setManager(this.manager); 
  	bean.setTelephone(this.telephone); 
  	bean.setTax(this.tax); 
  	bean.setAddress(this.address); 
  	bean.setCreateDate(this.createDate); 
  	bean =shopService.selectByPrimaryKey(bean);
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setShoptype(this.shoptype); 
  	bean.setManager(this.manager); 
  	bean.setTelephone(this.telephone); 
  	bean.setTax(this.tax); 
  	bean.setAddress(this.address); 
  	bean.setCreateDate(this.createDate); 
	shopService.updateByPrimaryKeySelective(bean);
	javax.servlet.http.HttpServletRequest request =(javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST);
	Object empolyeeBean =  request.getSession().getAttribute("employee") ;
	if (  empolyeeBean != null ) {
		int refEmployeeDbid = ( ( Employee ) empolyeeBean).getDbid();
		 LogUtil.addLog(refEmployeeDbid, LogUtil.OPERATOR_KEY_UPDATE , Color.MODULE_ID );
	}
   	success = true ;
   	info = "Update Successful" ;
   	return SUCCESS;
  }

  @Action(value="deleteShop",results = {@Result(name = "success", type = "json")})
  public String  deleteShop() throws Exception{
  	Shop bean = new Shop();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setShoptype(this.shoptype); 
  	bean.setManager(this.manager); 
  	bean.setTelephone(this.telephone); 
  	bean.setTax(this.tax); 
  	bean.setAddress(this.address); 
  	bean.setCreateDate(this.createDate); 
	shopService.deleteByPrimaryKey(bean);
	javax.servlet.http.HttpServletRequest request =(javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST);
	Object empolyeeBean =  request.getSession().getAttribute("employee") ;
	if (  empolyeeBean != null ) {
		int refEmployeeDbid = ( ( Employee ) empolyeeBean).getDbid();
		 LogUtil.addLog(refEmployeeDbid, LogUtil.OPERATOR_KEY_DELETE , Color.MODULE_ID );
	}
   	return SUCCESS;
  }

  @Action(value="listShop",results = {@Result(name = "success", type = "json")})
  public String  listShop() throws Exception{
 	QryCondition qry = RequestUtil.getQryCondition(   (javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST)); 	PageBean pageBean = new PageBean();
	pageBean.setPageSize( limit );
	pageBean.setStartCount( start );
	totalProperty =shopService.getTotalRecords( qry, pageBean );
	shopPageBeans =shopService.getOnePageBeans( qry, pageBean );
   	return SUCCESS;
  }

  @Action("index")
  public String index() throws Exception{
   	return SUCCESS;
  }

}
